BEGIN TRANSACTION

DECLARE @tableName AS VARCHAR(MAX)

DECLARE TableCursor CURSOR FAST_FORWARD READ_ONLY FOR
SELECT name
FROM sys.tables st
LEFT JOIN sys.sysreferences ssr ON st.object_id = ssr.fkeyid
WHERE name LIKE 'aspnet%'
ORDER BY constid DESC

OPEN TableCursor

FETCH NEXT FROM TableCursor INTO @TableName

WHILE @@FETCH_STATUS = 0
BEGIN

IF(EXISTS(SELECT 1 FROM sys.tables WHERE name = @tableName))
BEGIN
	EXEC ('Drop Table ' + @tableName)
END

FETCH NEXT FROM TableCursor INTO @TableName

END

CLOSE TableCursor
DEALLOCATE TableCursor


DECLARE @ProcName AS VARCHAR(MAX)
DECLARE DeleteProcs  CURSOR FAST_FORWARD READ_ONLY FOR
SELECT NAME
FROM sys.procedures
WHERE name LIKE 'aspnet%' 
OPEN DeleteProcs
FETCH NEXT FROM DeleteProcs INTO @ProcName

WHILE @@FETCH_STATUS = 0
BEGIN

EXEC ('Drop Procedure ' + @ProcName)

FETCH NEXT FROM DeleteProcs INTO @ProcName

END

CLOSE DeleteProcs
DEALLOCATE DeleteProcs

COMMIT TRANSACTION